package main

// 各类SQL数据库从数据库中获取表名的常量。
const (
	mysqlOneTableSql = `select table_name from information_schema.tables where table_schema = ? and table_name in ('%s') and table_type = 'base table';`
	mysqlTableSql    = "SELECT `TABLE_NAME` AS 'table_name', `TABLE_COMMENT` AS 'table_comment' FROM information_schema.tables WHERE `TABLE_SCHEMA` = ?"
	// 注意: MysqlColumnSql 里面，where 后面的条件的顺序只能是 table_name = ? and table_schema = ? 不能写反了(因为3_schema.go文件中的方法就是根据这个顺序接收参数的!)
	mysqlColumnSql = "select `COLUMN_NAME` AS column_name,`DATA_TYPE` AS data_type, `COLUMN_KEY` AS column_key, " +
		"`IS_NULLABLE` AS is_nullable, `COLUMN_DEFAULT` AS column_default,`COLUMN_TYPE` AS column_type, `COLUMN_COMMENT` " +
		"AS column_comment from information_schema.columns where table_name = ? and table_schema = ?"
	mysqlTableComment = "SELECT `TABLE_COMMENT` FROM information_schema.tables WHERE table_name = ? and table_schema = ?"
	mysqlFieldSql     = `SELECT COLUMN_NAME fName,column_comment fDesc,DATA_TYPE dataType,
						IS_NULLABLE isNull,IFNULL(CHARACTER_MAXIMUM_LENGTH,0) sLength
			FROM information_schema.columns 
			WHERE table_schema = ? AND table_name = ?`
)

const (
	projectName = "gen"
	version     = "v0.1.0"
	copyright   = "2021.4"
	author      = "xxx"
	authorEmail = "xxx"
)

// 操作系统
const (
	unknown = iota
	darwin
	window
	linux
)

// 文件常量
const (
	fileConfig    = "config.toml"
	fileTableList = "table.go"  // table file
	fileInit      = "init.go"   // init file
	fileRouter    = "router.go" // example file
)

// 包常量
const (
	pkgRouter  = "router"  // 路由层包名
	pkgApi     = "api"     // api接口层包名 (mvc架构中 controller层包名)
	pkgService = "service" // 业务服务层包名
	pkgDao     = "dao"     // 表实体所在目录 (表实体文件的包)
	pkgConfig  = "config"  // 配置文件的包名
)

// 模板文件常量
const (
	tplService  = "asset/tpl/service.tpl" // 结构体模板
	tplEntity   = "asset/tpl/entity.tpl"  // 表entity的模板
	tplDao      = "asset/tpl/dao.tpl"     // 操作表的dao结构体
	tplApi      = "asset/tpl/api.tpl"
	tplObj      = "asset/tpl/obj.tpl"
	tplToml     = "asset/tpl/toml.tpl"
	tplHttp     = "asset/tpl/http.tpl"
	tplTables   = "asset/tpl/tables.tpl"   // 表结构模板
	tplInit     = "asset/tpl/init.tpl"     // init模板
	tplMarkdown = "asset/tpl/markdown.tpl" // markdown模板
	tplRouter   = "asset/tpl/router.tpl"   // example模板
)

//mysql类型 <=> golang类型
var mysqlTypeToGoType = map[string]string{
	"bit":       "bool",
	"tinyint":   "int",
	"smallint":  "int",
	"mediumint": "int",
	"int":       "int",
	"integer":   "int",
	"bigint":    "int",
	"float":     "float64",
	"double":    "float64",
	"decimal":   "float64",
	"date":      "string",
	"time":      "string",
	"year":      "string",
	"datetime":  "time.Time",
	"timestamp": "time.Time",
	//"datetime":   "string",
	//"timestamp":  "string",
	"char":       "string",
	"varchar":    "string",
	"tinyblob":   "string",
	"tinytext":   "string",
	"blob":       "string",
	"text":       "string",
	"mediumblob": "string",
	"mediumtext": "string",
	"longblob":   "string",
	"longtext":   "string",
	"varbinary":  "string",
}

// help list
var cmdHelp = []cmdEntity{
	//{"0", "设置生成代码的存放目录"},
	{"1", "生成表 markdown 文档"},
	{"2", "生成表的 model层 实体代码"},
	{"3", "生成表的 dao层 CRUD代码"},
	//{"4", "生成mvc基础代码"},
	//{"5", "查找或设置表名"},
	{"clear", "清屏"},
	{"help", "显示帮助列表"},
	{"quit", "退出"},
}
